home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / bookmark.el < prev    next >
Encoding:
Text File  |  1995-07-14  |  77.9 KB  |  2,188 lines

  1. ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later.
  2.  
  3. ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation
  4.  
  5. ;; Author: Karl Fogel <kfogel@cyclic.com>
  6. ;; Maintainer: Karl Fogel <kfogel@cyclic.com>
  7. ;; Created: July, 1993
  8. ;; Author's Update Number: 2.6.14
  9. ;; Keywords: bookmarks, placeholders, annotations
  10.  
  11. ;;; Summary:
  12. ;; This package is for setting "bookmarks" in files.  A bookmark
  13. ;; associates a string with a location in a certain file.  Thus, you
  14. ;; can navigate your way to that location by providing the string.
  15. ;; See the "User Variables" section for customizations.
  16.  
  17. ;;; Copyright info:
  18. ;; This file is part of GNU Emacs.
  19.  
  20. ;; GNU Emacs is free software; you can redistribute it and/or modify
  21. ;; it under the terms of the GNU General Public License as published by
  22. ;; the Free Software Foundation; either version 2, or (at your option)
  23. ;; any later version.
  24.  
  25. ;; GNU Emacs is distributed in the hope that it will be useful,
  26. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  28. ;; GNU General Public License for more details.
  29.  
  30. ;; You should have received a copy of the GNU General Public License
  31. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  32. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  33.  
  34. ;;; Synched up with: FSF 19.29.
  35.  
  36. ;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
  37. ;; then implementing the bookmark-current-bookmark idea.  He even
  38. ;; sent *patches*, bless his soul...
  39.  
  40. ;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
  41. ;; fixing and improving bookmark-time-to-save-p.
  42.  
  43. ;; Thanks go to Andrew V. Klein <avk@cig.mot.com> for the code that
  44. ;; sorts the alist before presenting it to the user (in bookmark-bmenu-list
  45. ;; and the menu-bar).
  46.  
  47. ;; And much thanks to David Hughes <djh@harston.cv.com> for many small
  48. ;; suggestions and the code to implement them (like
  49. ;; bookmark-bmenu-check-position, and some of the Lucid compatibility
  50. ;; stuff).
  51.  
  52. ;; Kudos (whatever they are) go to Jim Blandy <jimb@cyclic.com>
  53. ;; for his eminently sensible suggestion to separate bookmark-jump
  54. ;; into bookmark-jump and bookmark-jump-noselect, which made many
  55. ;; other things cleaner as well.
  56.  
  57. ;; Thanks to Roland McGrath for encouragement and help with defining
  58. ;; autoloads on the menu-bar.
  59.  
  60. ;; Jonathan Stigelman <stig@key.amdahl.com> gave patches for default
  61. ;; values in bookmark-jump and bookmark-set.  Everybody please keep
  62. ;; all the keystrokes they save thereby and send them to him at the
  63. ;; end of each year :-)  (No, seriously, thanks Jonathan!)
  64.  
  65. ;; Buckets of gratitude to John Grabowski <johng@media.mit.edu> for
  66. ;; thinking up the annotations feature and implementing it so well.
  67.  
  68. ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
  69. ;; <olstad@msc.edu>.
  70.  
  71. ;; Thanks to Mikio Nakajima <PBC01764@niftyserve.or.jp> for many bugs
  72. ;; reported and fixed.
  73.  
  74. ;; Thank you, Michael Kifer, for contributing the XEmacs support.
  75.  
  76. ;; Enough with the credits already, get on to the good stuff:
  77.  
  78. ;; FAVORITE CHINESE RESTAURANT: 
  79. ;; Boy, that's a tough one.  Probably Hong Min, or maybe Emperor's
  80. ;; Choice (both in Chicago's Chinatown).  Well, both.  How about you?
  81.  
  82.  
  83. (require 'pp)
  84.  
  85.  
  86. ;;;; Code:
  87.  
  88. ;;; Misc comments:
  89. ;;
  90. ;; If variable bookmark-use-annotations is non-nil, an annotation is
  91. ;; queried for when setting a bookmark.  
  92. ;;
  93. ;; The bookmark list is sorted lexically by default, but you can turn
  94. ;; this off by setting bookmark-sort-flag to nil.  If it is nil, then
  95. ;; the list will be presented in the order it is recorded
  96. ;; (chronologically), which is actually fairly useful as well.
  97.  
  98. ;;; User Variables
  99.  
  100. (defvar bookmark-use-annotations nil
  101.   "*If non-nil, saving a bookmark will query for an annotation in a
  102. buffer.")
  103.  
  104.  
  105. (defvar bookmark-save-flag t
  106.   "*Controls when Emacs saves bookmarks to a file.
  107. --> Nil means never save bookmarks, except when `bookmark-save' is
  108.     explicitly called \(\\[bookmark-save]\).
  109. --> t means save bookmarks when Emacs is killed.
  110. --> Otherise, it should be a number that is the frequency with which
  111.     the bookmark list is saved \(i.e.: the number of times which
  112.     Emacs' bookmark list may be modified before it is automatically
  113.     saved.\).  If it is a number, Emacs will also automatically save
  114.     bookmarks when it is killed.
  115.  
  116. Therefore, the way to get it to save every time you make or delete a
  117. bookmark is to set this variable to 1 \(or 0, which produces the same
  118. behavior.\)
  119.  
  120. To specify the file in which to save them, modify the variable
  121. bookmark-default-file, which is `~/.emacs.bmk' by default.")
  122.  
  123.  
  124. (defconst bookmark-old-default-file "~/.emacs-bkmrks"
  125.   "*The .emacs.bmk file used to be called this.")
  126.  
  127.  
  128. ;; defvarred to avoid a compilation warning:
  129. (defvar bookmark-file nil
  130.   "Old name for `bookmark-default-file'.")
  131.  
  132. (defvar bookmark-default-file
  133.   (if bookmark-file
  134.       ;; In case user set `bookmark-file' in her .emacs:
  135.       bookmark-file
  136.     (if (eq system-type 'ms-dos)
  137.         "~/emacs.bmk" ; Cannot have initial dot [Yuck!]
  138.       "~/.emacs.bmk"))
  139.   "*File in which to save bookmarks by default.")
  140.  
  141.  
  142. (defvar bookmark-version-control 'nospecial
  143.   "*Whether or not to make numbered backups of the bookmark file.
  144. It can have four values: t, nil, `never', and `nospecial'.
  145. The first three have the same meaning that they do for the
  146. variable `version-control', and the final value `nospecial' means just
  147. use the value of `version-control'.")
  148.  
  149.  
  150. (defvar bookmark-completion-ignore-case t
  151.   "*Non-nil means bookmark functions ignore case in completion.")
  152.  
  153.  
  154. (defvar bookmark-sort-flag t
  155.   "*Non-nil means that bookmarks will be displayed sorted by bookmark
  156. name.  Otherwise they will be displayed in LIFO order (that is, most
  157. recently set ones come first, oldest ones come last).")
  158.  
  159.  
  160. (defvar bookmark-automatically-show-annotations t
  161.   "*Nil means don't show annotations when jumping to a bookmark.")
  162.  
  163.  
  164. (defvar bookmark-bmenu-file-column 30
  165.   "*Column at which to display filenames in a buffer listing bookmarks.
  166. You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames].")
  167.  
  168.  
  169. (defvar bookmark-bmenu-toggle-filenames t
  170.   "*Non-nil means show filenames when listing bookmarks.
  171. This may result in truncated bookmark names.  To disable this, put the
  172. following in your .emacs:
  173.  
  174. \(setq bookmark-bmenu-toggle-filenames nil\)")
  175.  
  176.  
  177. (defvar bookmark-menu-length 70
  178.   "*Maximum length of a bookmark name displayed on a popup menu.")
  179.  
  180.  
  181. ;;; No user-serviceable parts beyond this point.
  182.  
  183. ;; Is it XEmacs?
  184. (defconst bookmark-xemacsp
  185.   (string-match "\\(Lucid\\|Xemacs\\)" emacs-version))
  186.  
  187.  
  188. ;; Added  for lucid emacs  compatibility, db
  189. (or (fboundp 'defalias)  (fset 'defalias 'fset))
  190.  
  191. ;; suggested for lucid compatibility by david hughes:
  192. (or (fboundp 'frame-height)  (defalias 'frame-height 'screen-height))
  193.  
  194.  
  195.  
  196. ;;; Keymap stuff:
  197. ;; some people have C-x r set to rmail or whatever.  We don't want to
  198. ;; assume that C-x r is a prefix map just because it's distributed
  199. ;; that way...
  200. ;; These are the distribution keybindings suggested by RMS, everything
  201. ;; else will be done with M-x or the menubar:
  202. ;;;###autoload
  203. (if (symbolp (key-binding "\C-xr"))
  204.     nil
  205.   (progn (define-key ctl-x-map "rb" 'bookmark-jump)
  206.          (define-key ctl-x-map "rm" 'bookmark-set)
  207.          (define-key ctl-x-map "rl" 'bookmark-bmenu-list)))
  208.  
  209. ;; define the map, so it can be bound by those who desire to do so:
  210.  
  211. ;;;###autoload
  212. (defvar bookmark-map nil
  213.   "Keymap containing bindings to bookmark functions.
  214. It is not bound to any key by default: to bind it
  215. so that you have a bookmark prefix, just use `global-set-key' and bind a
  216. key of your choice to `bookmark-map'.  All interactive bookmark
  217. functions have a binding in this keymap.")
  218.  
  219. ;;;###autoload
  220. (define-prefix-command 'bookmark-map)
  221.  
  222. ;; Read the help on all of these functions for details...
  223. ;;;###autoload
  224. (define-key bookmark-map "x" 'bookmark-set)
  225. ;;;###autoload
  226. (define-key bookmark-map "m" 'bookmark-set) ; "m" for "mark"
  227. ;;;###autoload
  228. (define-key bookmark-map "j" 'bookmark-jump)
  229. ;;;###autoload
  230. (define-key bookmark-map "g" 'bookmark-jump) ; "g" for "go"
  231. ;;;###autoload
  232. (define-key bookmark-map "i" 'bookmark-insert)
  233. ;;;###autoload
  234. (define-key bookmark-map "e" 'edit-bookmarks)
  235. ;;;###autoload
  236. (define-key bookmark-map "f" 'bookmark-insert-location) ; "f" for "find"
  237. ;;;###autoload
  238. (define-key bookmark-map "r" 'bookmark-rename)
  239. ;;;###autoload
  240. (define-key bookmark-map "d" 'bookmark-delete)
  241. ;;;###autoload
  242. (define-key bookmark-map "l" 'bookmark-load)
  243. ;;;###autoload
  244. (define-key bookmark-map "w" 'bookmark-write)
  245. ;;;###autoload
  246. (define-key bookmark-map "s" 'bookmark-save)
  247.  
  248.  
  249. ;;; The annotation maps.
  250. (defvar bookmark-read-annotation-mode-map (copy-keymap text-mode-map)
  251.   "Keymap for composing an annotation for a bookmark.")
  252.  
  253. (define-key bookmark-read-annotation-mode-map "\C-c\C-c"
  254.   'bookmark-send-annotation)
  255.  
  256.  
  257.  
  258. ;;; Core variables and data structures:
  259. (defvar bookmark-alist ()
  260.   "Association list of bookmarks and their records.
  261. You probably don't want to change the value of this alist yourself;
  262. instead, let the various bookmark functions do it for you.
  263.  
  264. The format of the alist is
  265.  
  266.        \(BOOKMARK1 BOOKMARK2 ...\)
  267.  
  268. where each BOOKMARK is of the form
  269.  
  270. \(NAME
  271.   \(filename . FILE\)
  272.   \(front-context-string . FRONT-STR\)
  273.   \(rear-context-string  . REAR-STR\)
  274.   \(position . POS\)
  275.   \(info-node . POS\)
  276.   \(annotation . ANNOTATION\)\)
  277.  
  278. So the cdr of each bookmark is an alist too.
  279. `info-node' is optional, by the way.")
  280.  
  281.  
  282. (defvar bookmarks-already-loaded nil)
  283.  
  284.  
  285. ;; just add the hook to make sure that people don't lose bookmarks
  286. ;; when they kill Emacs, unless they don't want to save them.
  287. ;;;Don't ###autoload this, there's no need. -jwz
  288. (add-hook 'kill-emacs-hook
  289.           (function
  290.            (lambda () (and (featurep 'bookmark)
  291.                            bookmark-alist
  292.                            (bookmark-time-to-save-p t)
  293.                            (bookmark-save)))))
  294.  
  295. ;; more stuff added by db.
  296.  
  297. (defvar bookmark-current-bookmark nil 
  298.   "Name of bookmark most recently used in the current file.
  299. It is buffer local, used to make moving a bookmark forward
  300. through a file easier.")
  301.  
  302. (make-variable-buffer-local 'bookmark-current-bookmark)
  303.  
  304.  
  305. (defvar bookmark-alist-modification-count 0
  306.   "Number of modifications to bookmark list since it was last saved.")
  307.  
  308.  
  309. (defvar bookmark-search-size 16
  310.   "Length of the context strings recorded on either side of a bookmark.")
  311.  
  312.  
  313. (defvar bookmark-current-point 0)
  314. (defvar bookmark-yank-point 0)
  315. (defvar bookmark-current-buffer nil)
  316.  
  317.  
  318.  
  319. ;; Helper functions.
  320.  
  321. ;; Only functions on this page and the next one (file formats) need to
  322. ;; know anything about the format of bookmark-alist entries.
  323. ;; Everyone else should go through them.
  324.  
  325. (defun bookmark-name-from-full-record (full-record)
  326.   "Return name of FULL-RECORD \(an alist element instead of a string\)."
  327.   (car full-record))
  328.  
  329.  
  330. (defun bookmark-all-names ()
  331.   "Return a list of all current bookmark names."
  332.   (bookmark-maybe-load-default-file)
  333.   (mapcar
  334.    (lambda (full-record)
  335.      (bookmark-name-from-full-record full-record))
  336.    bookmark-alist))
  337.  
  338.  
  339. (defun bookmark-get-bookmark (bookmark)
  340.   "Return the full entry for BOOKMARK in bookmark-alist."
  341.   (assoc bookmark bookmark-alist))
  342.  
  343.  
  344. (defun bookmark-get-bookmark-record (bookmark)
  345.   "Return the guts of the entry for BOOKMARK in bookmark-alist.
  346. That is, all information but the name."
  347.   (car (cdr (bookmark-get-bookmark bookmark))))
  348.  
  349.  
  350. (defun bookmark-set-name (bookmark newname)
  351.   "Set BOOKMARK's name to NEWNAME."
  352.   (setcar (bookmark-get-bookmark bookmark) newname))
  353.  
  354.  
  355. (defun bookmark-get-annotation (bookmark)
  356.   "Return the annotation of BOOKMARK, or nil if none."
  357.   (cdr (assq 'annotation (bookmark-get-bookmark-record bookmark))))
  358.  
  359.  
  360. (defun bookmark-set-annotation (bookmark ann)
  361.   "Set the annotation of BOOKMARK to ANN."
  362.   (let ((cell (assq 'annotation (bookmark-get-bookmark-record bookmark))))
  363.     (if cell
  364.         (setcdr cell ann)
  365.       (nconc (bookmark-get-bookmark-record bookmark)
  366.              (list (cons 'annotation ann))))))
  367.  
  368.  
  369. (defun bookmark-get-filename (bookmark)
  370.   "Return the full filename of BOOKMARK."
  371.   (cdr (assq 'filename (bookmark-get-bookmark-record bookmark))))
  372.  
  373.  
  374. (defun bookmark-set-filename (bookmark filename)
  375.   "Set the full filename of BOOKMARK to FILENAME."
  376.   (let ((cell (assq 'filename (bookmark-get-bookmark-record bookmark))))
  377.     (if cell
  378.         (setcdr cell filename)
  379.       (nconc (bookmark-get-bookmark-record bookmark)
  380.              (list (cons 'filename filename))))))
  381.  
  382.  
  383. (defun bookmark-get-position (bookmark)
  384.   "Return the position \(i.e.: point\) of BOOKMARK."
  385.   (cdr (assq 'position (bookmark-get-bookmark-record bookmark))))
  386.  
  387.  
  388. (defun bookmark-set-position (bookmark position)
  389.   "Set the position \(i.e.: point\) of BOOKMARK to POSITION."
  390.   (let ((cell (assq 'position (bookmark-get-bookmark-record bookmark))))
  391.     (if cell
  392.         (setcdr cell position)
  393.       (nconc (bookmark-get-bookmark-record bookmark)
  394.              (list (cons 'position position))))))
  395.  
  396.  
  397. (defun bookmark-get-front-context-string (bookmark)
  398.   "Return the front-context-string of BOOKMARK."
  399.   (cdr (assq 'front-context-string (bookmark-get-bookmark-record bookmark))))
  400.  
  401.  
  402. (defun bookmark-set-front-context-string (bookmark string)
  403.   "Set the front-context-string of BOOKMARK to STRING."
  404.   (let ((cell (assq 'front-context-string
  405.                     (bookmark-get-bookmark-record bookmark))))
  406.     (if cell
  407.         (setcdr cell string)
  408.       (nconc (bookmark-get-bookmark-record bookmark)
  409.              (list (cons 'front-context-string string))))))
  410.  
  411.  
  412. (defun bookmark-get-rear-context-string (bookmark)
  413.   "Return the rear-context-string of BOOKMARK."
  414.   (cdr (assq 'rear-context-string (bookmark-get-bookmark-record bookmark))))
  415.  
  416.  
  417. (defun bookmark-set-rear-context-string (bookmark string)
  418.   "Set the rear-context-string of BOOKMARK to STRING."
  419.   (let ((cell (assq 'rear-context-string
  420.                     (bookmark-get-bookmark-record bookmark))))
  421.     (if cell
  422.         (setcdr cell string)
  423.       (nconc (bookmark-get-bookmark-record bookmark)
  424.              (list (cons 'rear-context-string string))))))
  425.  
  426.  
  427. (defun bookmark-get-info-node (bookmark)
  428.   "Get the info node associated with BOOKMARK."
  429.   (cdr (assq 'info-node (bookmark-get-bookmark-record bookmark))))
  430.   
  431.  
  432. (defun bookmark-set-info-node (bookmark node)
  433.   "Set the Info node of BOOKMARK to NODE."
  434.   (let ((cell (assq 'info-node
  435.                     (bookmark-get-bookmark-record bookmark))))
  436.     (if cell
  437.         (setcdr cell node)
  438.       (nconc (bookmark-get-bookmark-record bookmark)
  439.              (list (cons 'info-node node))))))
  440.   
  441.  
  442. (defvar bookmark-history nil
  443.   "The history list for bookmark functions.")
  444.  
  445.  
  446. (defun bookmark-completing-read (prompt &optional default)
  447.   "Prompting with PROMPT, read a bookmark name in completion.
  448. PROMPT will get a \": \" stuck on the end no matter what, so you
  449. probably don't want to include one yourself.
  450. Optional second arg DEFAULT is a string to return if the user enters
  451. the empty string."
  452.   (bookmark-maybe-load-default-file) ; paranoia
  453.   (let* ((completion-ignore-case bookmark-completion-ignore-case)
  454.          (default default)
  455.          (prompt (if default
  456.                      (concat prompt (format " (%s): " default))
  457.                    (concat prompt ": ")))
  458.          (str
  459.           (completing-read prompt
  460.                            bookmark-alist
  461.                            nil
  462.                            0
  463.                            nil
  464.                            'bookmark-history)))
  465.     (if (string-equal "" str)
  466.         (list default)
  467.       (list str))))
  468.  
  469.  
  470. (defmacro bookmark-maybe-historicize-string (string)
  471.   "Put STRING into the bookmark prompt history, if caller non-interactive.
  472. We need this because sometimes bookmark functions are invoked from
  473. menus, so `completing-read' never gets a chance to set `bookmark-history'."
  474.   (` (or
  475.       (interactive-p)
  476.       (setq bookmark-history (cons (, string) bookmark-history)))))
  477.  
  478.  
  479. (defun bookmark-make (name &optional annotation overwrite)
  480.   "Make a bookmark named NAME.
  481. Optional second arg ANNOTATION gives it an annotation.
  482. Optional third arg OVERWRITE means replace any existing bookmarks with
  483. this name."
  484.   (bookmark-maybe-load-default-file)
  485.   (if (and (bookmark-get-bookmark name) (not overwrite))
  486.       ;; already existing boookmark under that name and
  487.       ;; no prefix arg means just overwrite old bookmark
  488.       (setcdr (bookmark-get-bookmark name)
  489.               (list (bookmark-make-cell annotation)))
  490.     
  491.     ;; otherwise just cons it onto the front (either the bookmark
  492.     ;; doesn't exist already, or there is no prefix arg.  In either
  493.     ;; case, we want the new bookmark consed onto the alist...)
  494.     
  495.     (setq bookmark-alist
  496.           (cons
  497.            (list name 
  498.                  (bookmark-make-cell annotation))
  499.            bookmark-alist)))
  500.  
  501.   ;; Added by db
  502.   (setq bookmark-current-bookmark name)
  503.   (setq bookmark-alist-modification-count
  504.         (1+ bookmark-alist-modification-count))
  505.   (if (bookmark-time-to-save-p)
  506.       (bookmark-save)))
  507.  
  508.  
  509. (defun bookmark-make-cell (annotation)
  510.   "Return the record part of a new bookmark, given ANNOTATION.
  511. Must be at the correct position in the buffer in which the bookmark is
  512. being set.  This will change soon."
  513.   (` ((filename . (, (bookmark-buffer-file-name)))
  514.       (front-context-string
  515.        . (, (if (>= (- (point-max) (point)) bookmark-search-size)
  516.                 ;; strip text props via `format':
  517.         (let ((string
  518.                         (buffer-substring 
  519.                          (point)
  520.                          (+ (point) bookmark-search-size))))
  521.                   (set-text-properties 0 (length string) nil string)
  522.                   string)
  523.               nil)))
  524.       (rear-context-string
  525.        . (, (if (>= (- (point) (point-min)) bookmark-search-size)
  526.                 ;; strip text props via `format':
  527.         (let ((string
  528.                         (buffer-substring 
  529.                          (point)
  530.                          (- (point) bookmark-search-size))))
  531.                   (set-text-properties 0 (length string) nil string)
  532.                   string)
  533.               nil)))
  534.       (position . (, (point)))
  535.       (annotation . (, annotation)))))
  536.   
  537.  
  538. ;;; File format stuff
  539.  
  540. ;; The OLD format of the bookmark-alist was:
  541. ;;
  542. ;;       ((bookmark-name (filename
  543. ;;                        string-in-front
  544. ;;                        string-behind
  545. ;;                        point))
  546. ;;        ...)
  547. ;;
  548. ;; The NEW format of the bookmark-alist is:
  549. ;;
  550. ;;       ((bookmark-name ((filename . FILENAME)
  551. ;;                        (front-context-string . string-in-front)
  552. ;;                        (rear-context-string  . string-behind)
  553. ;;                        (position . POINT)
  554. ;;                        (annotation . annotation)
  555. ;;                        (whatever   . VALUE)
  556. ;;                        ...
  557. ;;                        ))
  558. ;;        ...)
  559. ;;
  560. ;;
  561. ;; I switched to using an internal as well as external alist because I
  562. ;; felt that would be a more flexible framework in which to add
  563. ;; features.  It means that the order in which values appear doesn't
  564. ;; matter, and it means that arbitrary values can be added without
  565. ;; risk of interfering with existing ones.
  566. ;;
  567. ;; BOOKMARK-NAME is the string the user gives the bookmark and
  568. ;; accesses it by from then on.  
  569. ;;
  570. ;; FILENAME is the location of the file in which the bookmark is set.
  571. ;;
  572. ;; STRING-IN-FRONT is a string of `bookmark-search-size' chars of
  573. ;; context in front of the point at which the bookmark is set.
  574. ;;
  575. ;; STRING-BEHIND is the same thing, but after the point.  
  576. ;;
  577. ;; The context strings exist so that modifications to a file don't
  578. ;; necessarily cause a bookmark's position to be invalidated. 
  579. ;; bookmark-jump will search for STRING-BEHIND and STRING-IN-FRONT in
  580. ;; case the file has changed since the bookmark was set.  It will
  581. ;; attempt to place the user before the changes, if there were any.
  582. ;; annotation is the annotation for the bookmark; it may not exist
  583. ;; (for backward compatibility), be nil (no annotation), or be a
  584. ;; string.
  585. ;;
  586. ;; ANNOTATION is an annotation for the bookmark.
  587.  
  588.  
  589. (defconst bookmark-file-format-version 1
  590.   "The current version of the format used by bookmark files.
  591. You should never need to change this.")
  592.  
  593.  
  594. (defconst bookmark-end-of-version-stamp-marker
  595.   "-*- End Of Bookmark File Format Version Stamp -*-\n"
  596.   "This string marks the end of the version stamp in a bookmark file.")
  597.  
  598.  
  599. (defun bookmark-alist-from-buffer ()
  600.   "Return a bookmark-alist (in any format) from the current buffer.
  601. The buffer must of course contain bookmark format information.
  602. Does not care from where in the buffer it is called, and does not
  603. affect point."
  604.   (save-excursion
  605.     (goto-char (point-min))
  606.     (if (search-forward bookmark-end-of-version-stamp-marker nil t)
  607.         (read (current-buffer))
  608.       ;; Else we're dealing with format version 0
  609.       (if (search-forward "(" nil t)
  610.           (progn
  611.             (forward-char -1)
  612.             (read (current-buffer)))
  613.         ;; Else no hope of getting information here.
  614.         (error "Not bookmark format.")))))
  615.  
  616.  
  617. (defun bookmark-upgrade-version-0-alist (old-list)
  618.   "Upgrade a version 0 alist OLD-LIST to the current version."
  619.   (mapcar
  620.    (lambda (bookmark)
  621.      (let* ((name      (car bookmark))
  622.             (record    (car (cdr bookmark)))
  623.             (filename  (nth 0 record))
  624.             (front-str (nth 1 record))
  625.             (rear-str  (nth 2 record))
  626.             (position  (nth 3 record))
  627.             (ann       (nth 4 record)))
  628.        (list
  629.         name
  630.         (` ((filename             .    (, filename))
  631.             (front-context-string .    (, (or front-str "")))
  632.             (rear-context-string  .    (, (or rear-str  "")))
  633.             (position             .    (, position))
  634.             (annotation           .    (, ann)))))))
  635.    old-list))
  636.  
  637.  
  638. (defun bookmark-upgrade-file-format-from-0 ()
  639.   "Upgrade a bookmark file of format 0 (the original format) to format 1.
  640. This expects to be called from point-min in a bookmark file."
  641.   (message "Upgrading bookmark format from 0 to %d..."
  642.            bookmark-file-format-version)
  643.   (let* ((old-list (bookmark-alist-from-buffer))
  644.          (new-list (bookmark-upgrade-version-0-alist old-list)))
  645.     (delete-region (point-min) (point-max))
  646.     (bookmark-insert-file-format-version-stamp)
  647.     (pp new-list (current-buffer))
  648.     (save-buffer))
  649.   (goto-char (point-min))
  650.   (message "Upgrading bookmark format from 0 to %d... done."
  651.            bookmark-file-format-version)
  652.   )
  653.  
  654.  
  655. (defun bookmark-grok-file-format-version ()
  656.   "Return an integer which is the file-format version of this bookmark file.
  657. This expects to be called from point-min in a bookmark file."
  658.   (if (looking-at "^;;;;")
  659.       (save-excursion
  660.         (save-match-data
  661.           (re-search-forward "[0-9]")
  662.           (forward-char -1)
  663.           (read (current-buffer))))
  664.     ;; Else this is format version 0, the original one, which didn't
  665.     ;; even have version stamps.
  666.     0))
  667.  
  668.  
  669. (defun bookmark-maybe-upgrade-file-format ()
  670.   "Check the file-format version of this bookmark file.
  671. If the version is not up-to-date, upgrade it automatically.
  672. This expects to be called from point-min in a bookmark file."
  673.   (let ((version (bookmark-grok-file-format-version)))
  674.     (cond
  675.      ((= version bookmark-file-format-version)
  676.       ) ; home free -- version is current
  677.      ((= version 0)
  678.       (bookmark-upgrade-file-format-from-0))
  679.      (t
  680.       (error "Bookmark file format version strangeness.")))))
  681.  
  682.  
  683. (defun bookmark-insert-file-format-version-stamp ()
  684.   "Insert text indicating current version of bookmark file-format."
  685.   (insert
  686.    (format ";;;; Emacs Bookmark Format Version %d ;;;;\n"
  687.            bookmark-file-format-version))
  688.   (insert ";;; This format is meant to be slightly human-readable;\n"
  689.           ";;; nevertheless, you probably don't want to edit it.\n"
  690.           ";;; "
  691.           bookmark-end-of-version-stamp-marker))
  692.  
  693.  
  694. ;;; end file-format stuff
  695.  
  696.  
  697. ;;; Core code:
  698.  
  699. ;;;###autoload
  700. (defun bookmark-set (&optional name parg)
  701.   "Set a bookmark named NAME inside a file.
  702. If name is nil, then the user will be prompted.
  703. With prefix arg, will not overwrite a bookmark that has the same name
  704. as NAME if such a bookmark already exists, but instead will \"push\"
  705. the new bookmark onto the bookmark alist.  Thus the most recently set
  706. bookmark with name NAME would be the one in effect at any given time,
  707. but the others are still there, should you decide to delete the most
  708. recent one.
  709.  
  710. To yank words from the text of the buffer and use them as part of the
  711. bookmark name, type C-w while setting a bookmark.  Successive C-w's
  712. yank successive words.
  713.  
  714. Typing C-u inserts the name of the last bookmark used in the buffer
  715. \(as an aid in using a single bookmark name to track your progress
  716. through a large file\).  If no bookmark was used, then C-u inserts the
  717. name of the file being visited.
  718.  
  719. Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
  720. and it removes only the first instance of a bookmark with that name from
  721. the list of bookmarks.\)"
  722.   (interactive (list nil current-prefix-arg))
  723.   (or
  724.    (bookmark-buffer-file-name)
  725.    (error "Buffer not visiting a file or directory."))
  726.  
  727.   (bookmark-maybe-load-default-file)
  728.  
  729.   (setq bookmark-current-point (point))
  730.   (setq bookmark-yank-point (point))
  731.   (setq bookmark-current-buffer (current-buffer))
  732.  
  733.   (let* ((default (or bookmark-current-bookmark
  734.                       (bookmark-buffer-name)))
  735.      (str
  736.       (or name
  737.               (read-from-minibuffer
  738.                (format "Set bookmark (%s): " default)
  739.                nil
  740.                (let ((now-map (copy-keymap minibuffer-local-map)))
  741.                  (progn (define-key now-map  "\C-w" 
  742.                           'bookmark-yank-word)
  743.                         (define-key now-map  "\C-u" 
  744.                           'bookmark-insert-current-bookmark))
  745.                  now-map))))
  746.      (annotation nil))
  747.     (and (string-equal str "") (setq str default))
  748.     ;; Ask for an annotation buffer for this bookmark 
  749.     (if bookmark-use-annotations
  750.     (bookmark-read-annotation parg str)
  751.       (progn
  752.     (bookmark-make str annotation parg)
  753.         ;; In Info, there's a little more information to record:
  754.         (if (eq major-mode 'Info-mode)
  755.             (bookmark-set-info-node str Info-current-node))
  756.     (setq bookmark-current-bookmark str)
  757.     (bookmark-bmenu-surreptitiously-rebuild-list)
  758.     (goto-char bookmark-current-point)))))
  759.  
  760.  
  761. (defun bookmark-kill-line (&optional newline-too)
  762.   "Kill from point to end of line.
  763. If optional arg NEWLINE-TOO is non-nil, delete the newline too.
  764. Does not affect the kill-ring."
  765.   (let ((eol (save-excursion (end-of-line) (point))))
  766.     (delete-region (point) eol)
  767.     (if (and newline-too (looking-at "\n"))
  768.         (delete-char 1))))
  769.  
  770.  
  771. ;; Defvars to avoid compilation warnings:
  772. (defvar bookmark-annotation-paragraph nil)
  773. (defvar bookmark-annotation-name nil)
  774. (defvar bookmark-annotation-buffer nil)
  775. (defvar bookmark-annotation-file nil)
  776. (defvar bookmark-annotation-point nil)
  777.  
  778.  
  779. (defun bookmark-send-annotation ()
  780.   "After remove lines beginning with '#', use the contents of this buffer
  781. as the annotation for a bookmark, and store it in the bookmark list with
  782. the bookmark (and file, and point) specified in buffer local variables."
  783.   (interactive)
  784.   (if (not (eq major-mode 'bookmark-read-annotation-mode))
  785.       (error "Not in bookmark-read-annotation-mode."))
  786.   (goto-char (point-min))
  787.   (while (< (point) (point-max))
  788.     (if (looking-at "^#")
  789.         (bookmark-kill-line t)
  790.       (forward-line 1)))
  791.   (let ((annotation (buffer-substring (point-min) (point-max)))
  792.     (parg bookmark-annotation-paragraph)
  793.     (bookmark bookmark-annotation-name)
  794.     (pt bookmark-annotation-point)
  795.     (buf bookmark-annotation-buffer))
  796.     ;; for bookmark-make-cell to work, we need to be
  797.     ;; in the relevant buffer, at the relevant point.
  798.     ;; Actually, bookmark-make-cell should probably be re-written,
  799.     ;; to avoid this need.  Should I handle the error if a buffer is
  800.     ;; killed between "C-x r m" and a "C-c C-c" in the annotation buffer?
  801.     (save-excursion 
  802.       (pop-to-buffer buf)
  803.       (goto-char pt)
  804.       (bookmark-make bookmark annotation parg)
  805.       (setq bookmark-current-bookmark bookmark))
  806.     (bookmark-bmenu-surreptitiously-rebuild-list)
  807.     (goto-char bookmark-current-point))
  808.   (kill-buffer (current-buffer)))
  809.  
  810.  
  811. (defun bookmark-default-annotation-text (bookmark)
  812.   (concat "#  Type the annotation for bookmark '" bookmark "' here.\n"
  813.       "#  All lines which start with a '#' will be deleted.\n"
  814.       "#  Type C-c C-c when done.\n#\n"
  815.       "#  Author: " (user-full-name) " <" (user-login-name) "@"
  816.       (system-name) ">\n"
  817.       "#  Date:    " (current-time-string) "\n"))
  818.  
  819.  
  820. (defvar bookmark-read-annotation-text-func 'bookmark-default-annotation-text
  821.   "A variable containing a function which returns the text to insert
  822. into an annotation compisition buffer.  It takes the name of the bookmark,
  823. as a string, as an arg.")
  824.  
  825.  
  826. (defun bookmark-read-annotation-mode (buf point parg bookmark)
  827.   "Mode for composing annotations for a bookmark.
  828. Wants BUF POINT PARG and BOOKMARK.
  829. When you have finished composing, type \\[bookmark-send-annotation] to send
  830. the annotation.
  831.  
  832. \\{bookmark-read-annotation-mode-map}
  833. "
  834.   (interactive)
  835.   (kill-all-local-variables)
  836.   (make-local-variable 'bookmark-annotation-paragraph)
  837.   (make-local-variable 'bookmark-annotation-name)
  838.   (make-local-variable 'bookmark-annotation-buffer)
  839.   (make-local-variable 'bookmark-annotation-file)
  840.   (make-local-variable 'bookmark-annotation-point)
  841.   (setq bookmark-annotation-paragraph parg)
  842.   (setq bookmark-annotation-name bookmark)
  843.   (setq bookmark-annotation-buffer buf)
  844.   (setq bookmark-annotation-file (buffer-file-name buf))
  845.   (setq bookmark-annotation-point point)
  846.   (use-local-map bookmark-read-annotation-mode-map)
  847.   (setq major-mode 'bookmark-read-annotation-mode)
  848.   (insert (funcall bookmark-read-annotation-text-func bookmark))
  849.   (run-hooks 'text-mode-hook))
  850.  
  851.  
  852. (defun bookmark-read-annotation (parg bookmark)
  853.   "Pop up a buffer for entering a bookmark annotation.  Text surrounding
  854. the bookmark is PARG; the bookmark name is BOOKMARK."
  855.   (let ((buf (current-buffer))
  856.     (point (point)))
  857.     (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
  858.     (bookmark-read-annotation-mode buf point parg bookmark)))
  859.  
  860.  
  861. (defvar bookmark-edit-annotation-mode-map (copy-keymap text-mode-map)
  862.   "Keymap for editing an annotation of a bookmark.")
  863.  
  864.  
  865. (define-key bookmark-edit-annotation-mode-map "\C-c\C-c"
  866.   'bookmark-send-edited-annotation)
  867.  
  868.  
  869. (defun bookmark-edit-annotation-mode (bookmark)
  870.   "Mode for editing the annotation of bookmark BOOKMARK.
  871. When you have finished composing, type \\[bookmark-send-annotation].
  872.  
  873. \\{bookmark-edit-annotation-mode-map}
  874. "
  875.   (interactive)
  876.   (kill-all-local-variables)
  877.   (make-local-variable 'bookmark-annotation-name)
  878.   (setq bookmark-annotation-name bookmark)
  879.   (use-local-map bookmark-edit-annotation-mode-map)
  880.   (setq major-mode 'bookmark-edit-annotation-mode)
  881.   (insert (funcall bookmark-read-annotation-text-func bookmark))
  882.   (let ((annotation (bookmark-get-annotation bookmark)))
  883.     (if (and (not (eq annotation nil))
  884.          (not (string-equal annotation "")))
  885.     (insert annotation)))
  886.   (run-hooks 'text-mode-hook))
  887.  
  888.  
  889. (defun bookmark-send-edited-annotation ()
  890.   "After remove lines beginning with '#', use the contents of this buffer
  891. as the new annotation for a bookmark."
  892.   (interactive)
  893.   (if (not (eq major-mode 'bookmark-edit-annotation-mode))
  894.       (error "Not in bookmark-edit-annotation-mode."))
  895.   (goto-char (point-min))
  896.   (while (< (point) (point-max))
  897.     (if (looking-at "^#")
  898.         (bookmark-kill-line t)
  899.       (forward-line 1)))
  900.   (let ((annotation (buffer-substring (point-min) (point-max)))
  901.     (bookmark bookmark-annotation-name))
  902.     (bookmark-set-annotation bookmark annotation)
  903.     (bookmark-bmenu-surreptitiously-rebuild-list)
  904.     (goto-char bookmark-current-point))
  905.   (kill-buffer (current-buffer)))
  906.  
  907.  
  908. (defun bookmark-edit-annotation (bookmark)
  909.   "Pop up a buffer for editing bookmark BOOKMARK's annotation."
  910.   (let ((buf (current-buffer))
  911.     (point (point)))
  912.     (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
  913.     (bookmark-edit-annotation-mode bookmark)))
  914.  
  915.  
  916. (defun bookmark-insert-current-bookmark ()
  917.   "Insert this buffer's value of bookmark-current-bookmark, default
  918. to file name if it's nil."
  919.   (interactive)
  920.   (let ((str
  921.      (save-excursion
  922.        (set-buffer bookmark-current-buffer)
  923.        bookmark-current-bookmark)))
  924.     (if str (insert str) (bookmark-insert-buffer-name))))
  925.  
  926.  
  927. (defun bookmark-insert-buffer-name ()
  928.   "Insert the name (sans path) of the current file into the bookmark
  929. name that is being set."
  930.   (interactive)
  931.   (let ((str
  932.          (save-excursion
  933.            (set-buffer bookmark-current-buffer)
  934.            (bookmark-buffer-name))))
  935.     (insert str)))
  936.  
  937.  
  938. (defun bookmark-buffer-name ()
  939.   "Return the name of the current buffer's file, non-directory.
  940. In Info, return the current node."
  941.   (cond
  942.    ;; Are we in Info?
  943.    ((string-equal mode-name "Info") Info-current-node)
  944.    ;; Or are we a file?
  945.    (buffer-file-name (file-name-nondirectory buffer-file-name))
  946.    ;; Or are we a directory?
  947.    ((and (boundp 'dired-directory) dired-directory)
  948.     (let* ((dirname (if (stringp dired-directory)
  949.                         dired-directory
  950.                       (car dired-directory)))
  951.            (idx (1- (length dirname))))
  952.       ;; Strip the trailing slash.
  953.       (if (= ?/ (aref dirname idx))
  954.           (file-name-nondirectory (substring dirname 0 idx))
  955.         ;; Else return the current-buffer
  956.         (buffer-name (current-buffer)))))
  957.    ;; If all else fails, use the buffer's name.
  958.    (t
  959.     (buffer-name (current-buffer)))))
  960.  
  961.  
  962. (defun bookmark-yank-word ()
  963.   (interactive)
  964.   ;; get the next word from the buffer and append it to the name of
  965.   ;; the bookmark currently being set.
  966.   (let ((string (save-excursion
  967.                     (set-buffer bookmark-current-buffer)
  968.                     (goto-char bookmark-yank-point)
  969.                     (buffer-substring
  970.                      (point)
  971.                      (save-excursion
  972.                        (forward-word 1)
  973.                        (setq bookmark-yank-point (point)))))))
  974.     (insert string)))
  975.  
  976.  
  977. (defun bookmark-buffer-file-name ()
  978.   "Return the current buffer's file in a way useful for bookmarks.
  979. For example, if this is a Info buffer, return the Info file's name."
  980.   (if (eq major-mode 'Info-mode)
  981.         Info-current-file
  982.     (or
  983.      buffer-file-name
  984.      (if (and (boundp 'dired-directory) dired-directory)
  985.          (if (stringp dired-directory)
  986.              dired-directory
  987.            (car dired-directory))))))
  988.  
  989.  
  990. (defun bookmark-maybe-load-default-file ()
  991.   (and (not bookmarks-already-loaded)
  992.        (null bookmark-alist)
  993.  
  994.        (prog2
  995.            (and
  996.             ;; Possibly the old bookmark file, "~/.emacs-bkmrks", needs
  997.             ;; to be renamed.
  998.             (file-exists-p (expand-file-name bookmark-old-default-file))
  999.             (not (file-exists-p (expand-file-name bookmark-default-file)))
  1000.             (rename-file (expand-file-name bookmark-old-default-file)
  1001.                          (expand-file-name bookmark-default-file)))
  1002.            ;; return t so the `and' will continue...
  1003.            t)
  1004.        
  1005.        (file-readable-p (expand-file-name bookmark-default-file))
  1006.        (progn
  1007.          (bookmark-load bookmark-default-file t t)
  1008.          (setq bookmarks-already-loaded t))))
  1009.  
  1010.  
  1011. (defun bookmark-maybe-sort-alist ()
  1012.   ;;Return the bookmark-alist for display.  If the bookmark-sort-flag
  1013.   ;;is non-nil, then return a sorted copy of the alist.
  1014.   (if bookmark-sort-flag
  1015.       (setq bookmark-alist
  1016.             (sort (copy-alist bookmark-alist)
  1017.                   (function
  1018.                    (lambda (x y) (string-lessp (car x) (car y))))))))
  1019.  
  1020.  
  1021. ;;;###autoload
  1022. (defun bookmark-jump (bookmark)
  1023.   "Jump to bookmark BOOKMARK (a point in some file).  
  1024. You may have a problem using this function if the value of variable
  1025. `bookmark-alist' is nil.  If that happens, you need to load in some
  1026. bookmarks.  See help on function `bookmark-load' for more about
  1027. this.
  1028.  
  1029. If the file pointed to by BOOKMARK no longer exists, you will be asked
  1030. if you wish to give the bookmark a new location, and bookmark-jump
  1031. will then jump to the new location, as well as recording it in place
  1032. of the old one in the permanent bookmark record."
  1033.   (interactive
  1034.    (bookmark-completing-read "Jump to bookmark" bookmark-current-bookmark))
  1035.   (bookmark-maybe-historicize-string bookmark)
  1036.   (let ((cell (bookmark-jump-noselect bookmark)))
  1037.     (and cell
  1038.          (switch-to-buffer (car cell))
  1039.          (goto-char (cdr cell))
  1040.      (if bookmark-automatically-show-annotations
  1041.              ;; if there is an annotation for this bookmark,
  1042.              ;; show it in a buffer.
  1043.              (bookmark-show-annotation bookmark)))))
  1044.  
  1045.  
  1046. (defun bookmark-jump-noselect (str)
  1047.   ;; a leetle helper for bookmark-jump :-)
  1048.   ;; returns (BUFFER . POINT)
  1049.   (bookmark-maybe-load-default-file)
  1050.   (let* ((file (expand-file-name (bookmark-get-filename str)))
  1051.          (forward-str            (bookmark-get-front-context-string str))
  1052.          (behind-str             (bookmark-get-rear-context-string str))
  1053.          (place                  (bookmark-get-position str))
  1054.          (info-node              (bookmark-get-info-node str))
  1055.          (orig-file              file)
  1056.          )
  1057.     (if (or
  1058.          (file-exists-p file)
  1059.          ;; else try some common compression extensions
  1060.          ;; and Emacs better handle it right!
  1061.          ;; Sigh: I think it may *not* be handled at the moment.  What
  1062.          ;; to do about this?
  1063.          (setq file
  1064.                (or
  1065.                 (let ((altname (concat file ".Z")))
  1066.                   (and (file-exists-p altname)
  1067.                        altname))
  1068.                 (let ((altname (concat file ".gz")))
  1069.                   (and (file-exists-p altname)
  1070.                        altname))
  1071.                 (let ((altname (concat file ".z")))
  1072.                   (and (file-exists-p altname)
  1073.                        altname)))))
  1074.         (save-excursion
  1075.           (if info-node
  1076.               ;; Info nodes must be visited with care.
  1077.               (progn
  1078.                 (require 'info)
  1079.                 (Info-find-node file info-node))
  1080.             ;; Else no Info.  Can do an ordinary find-file:
  1081.             (set-buffer (find-file-noselect file))
  1082.             (goto-char place))
  1083.  
  1084.           ;; Go searching forward first.  Then, if forward-str exists and
  1085.           ;; was found in the file, we can search backward for behind-str.
  1086.           ;; Rationale is that if text was inserted between the two in the
  1087.           ;; file, it's better to be put before it so you can read it,
  1088.           ;; rather than after and remain perhaps unaware of the changes.
  1089.           (if forward-str
  1090.               (if (search-forward forward-str (point-max) t)
  1091.                   (backward-char (length forward-str))))
  1092.           (if behind-str
  1093.               (if (search-backward behind-str (point-min) t)
  1094.                   (forward-char (length behind-str))))
  1095.           ;; added by db
  1096.           (setq bookmark-current-bookmark str)
  1097.           (cons (current-buffer) (point)))
  1098.       (progn
  1099.         (ding)
  1100.         (if (y-or-n-p (concat (file-name-nondirectory orig-file)
  1101.                               " nonexistent.  Relocate \""
  1102.                               str
  1103.                               "\"? "))
  1104.             (progn
  1105.               (bookmark-relocate str)
  1106.               ;; gasp!  It's a recursive function call in Emacs Lisp!
  1107.               (bookmark-jump-noselect str))
  1108.           (message 
  1109.            "Bookmark not relocated; consider removing it \(%s\)." str)
  1110.           nil)))))
  1111.  
  1112.  
  1113. ;;;###autoload
  1114. (defun bookmark-relocate (bookmark)
  1115.   "Relocate BOOKMARK -- prompts for a filename, and makes an already
  1116. existing bookmark point to that file, instead of the one it used to
  1117. point at.  Useful when a file has been renamed after a bookmark was
  1118. set in it."
  1119.   (interactive (bookmark-completing-read "Bookmark to relocate"))
  1120.   (bookmark-maybe-historicize-string bookmark)
  1121.   (bookmark-maybe-load-default-file)
  1122.   (let* ((bmrk-filename (bookmark-get-filename bookmark))
  1123.          (newloc (expand-file-name
  1124.                   (read-file-name
  1125.                    (format "Relocate %s to: " bookmark)
  1126.                    (file-name-directory bmrk-filename)))))
  1127.     (bookmark-set-filename bookmark newloc)))
  1128.  
  1129.  
  1130. ;;;###autoload
  1131. (defun bookmark-insert-location (bookmark &optional no-history)
  1132.   "Insert the name of the file associated with BOOKMARK.
  1133. Optional second arg NO-HISTORY means don't record this in the
  1134. minibuffer history list `bookmark-history'."
  1135.   (interactive (bookmark-completing-read "Insert bookmark location"))
  1136.   (or no-history (bookmark-maybe-historicize-string bookmark))
  1137.   (insert (bookmark-location bookmark)))
  1138.  
  1139.  
  1140. (defun bookmark-location (bookmark)
  1141.   "Return the name of the file associated with BOOKMARK."
  1142.   (bookmark-maybe-load-default-file)
  1143.   (bookmark-get-filename bookmark))
  1144.  
  1145.  
  1146. ;;;###autoload
  1147. (defun bookmark-rename (old &optional new)
  1148.   "Change the name of OLD bookmark to NEW name.  If called from
  1149. keyboard, prompts for OLD and NEW.  If called from menubar, OLD is
  1150. selected from a menu, and prompts for NEW.
  1151.  
  1152. If called from Lisp, prompts for NEW if only OLD was passed as an
  1153. argument.  If called with two strings, then no prompting is done.  You
  1154. must pass at least OLD when calling from Lisp.
  1155.  
  1156. While you are entering the new name, consecutive C-w's insert
  1157. consectutive words from the text of the buffer into the new bookmark
  1158. name."
  1159.   (interactive (bookmark-completing-read "Old bookmark name"))
  1160.   (bookmark-maybe-historicize-string old)
  1161.   (bookmark-maybe-load-default-file)
  1162.   (progn
  1163.     (setq bookmark-current-point (point))
  1164.     (setq bookmark-yank-point (point))
  1165.     (setq bookmark-current-buffer (current-buffer))
  1166.     (let ((newname
  1167.            (or new   ; use second arg, if non-nil
  1168.                (read-from-minibuffer
  1169.                 "New name: "
  1170.                 nil
  1171.                 (let ((now-map (copy-keymap minibuffer-local-map)))
  1172.                   (define-key now-map  "\C-w" 'bookmark-yank-word)
  1173.                   now-map)
  1174.                 nil
  1175.                 'bookmark-history))))
  1176.       (progn
  1177.     (bookmark-set-name old newname)
  1178.     (setq bookmark-current-bookmark newname)
  1179.         (bookmark-bmenu-surreptitiously-rebuild-list)
  1180.     (setq bookmark-alist-modification-count
  1181.           (1+ bookmark-alist-modification-count))
  1182.     (if (bookmark-time-to-save-p)
  1183.         (bookmark-save))))))
  1184.  
  1185.  
  1186. ;;;###autoload
  1187. (defun bookmark-insert (bookmark)
  1188.   "Insert the text of the file pointed to by bookmark BOOKMARK.  
  1189. You may have a problem using this function if the value of variable
  1190. `bookmark-alist' is nil.  If that happens, you need to load in some
  1191. bookmarks.  See help on function `bookmark-load' for more about
  1192. this."
  1193.   (interactive (bookmark-completing-read "Insert bookmark contents"))
  1194.   (bookmark-maybe-historicize-string bookmark)
  1195.   (bookmark-maybe-load-default-file)
  1196.   (let ((orig-point (point))
  1197.         (str-to-insert
  1198.          (save-excursion
  1199.            (set-buffer (car (bookmark-jump-noselect bookmark)))
  1200.            (buffer-substring (point-min) (point-max)))))
  1201.     (insert str-to-insert)
  1202.     (push-mark)
  1203.     (goto-char orig-point)))
  1204.  
  1205.  
  1206. ;;;###autoload
  1207. (defun bookmark-delete (bookmark &optional batch)
  1208.   "Delete BOOKMARK from the bookmark list.  
  1209. Removes only the first instance of a bookmark with that name.  If
  1210. there are one or more other bookmarks with the same name, they will
  1211. not be deleted.  Defaults to the \"current\" bookmark \(that is, the
  1212. one most recently used in this file, if any\).
  1213. Optional second arg BATCH means don't update the bookmark list buffer,
  1214. probably because we were called from there."
  1215.   (interactive
  1216.    (bookmark-completing-read "Delete bookmark" bookmark-current-bookmark))
  1217.   (bookmark-maybe-historicize-string bookmark)
  1218.   (bookmark-maybe-load-default-file)
  1219.   (let ((will-go (bookmark-get-bookmark bookmark)))
  1220.     (setq bookmark-alist (delq will-go bookmark-alist))
  1221.     ;; Added by db, nil bookmark-current-bookmark if the last
  1222.     ;; occurence has been deleted
  1223.     (or (bookmark-get-bookmark bookmark-current-bookmark)
  1224.         (setq bookmark-current-bookmark nil)))
  1225.   ;; Don't rebuild the list
  1226.   (if batch
  1227.       nil
  1228.     (bookmark-bmenu-surreptitiously-rebuild-list)
  1229.     (setq bookmark-alist-modification-count
  1230.           (1+ bookmark-alist-modification-count))
  1231.     (if (bookmark-time-to-save-p)
  1232.         (bookmark-save))))
  1233.  
  1234.  
  1235. (defun bookmark-time-to-save-p (&optional last-time)
  1236.   ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
  1237.   ;; finds out whether it's time to save bookmarks to a file, by
  1238.   ;; examining the value of variable bookmark-save-flag, and maybe
  1239.   ;; bookmark-alist-modification-count.  Returns t if they should be
  1240.   ;; saved, nil otherwise.  if last-time is non-nil, then this is
  1241.   ;; being called when emacs is killed.
  1242.   (cond (last-time 
  1243.      (and (> bookmark-alist-modification-count 0)
  1244.           bookmark-save-flag))
  1245.     ((numberp bookmark-save-flag)
  1246.      (>= bookmark-alist-modification-count bookmark-save-flag))
  1247.     (t
  1248.      nil)))
  1249.  
  1250.  
  1251. ;;;###autoload
  1252. (defun bookmark-write ()
  1253.   "Write bookmarks to a file \(for which the user will be prompted
  1254. interactively\).  Don't use this in Lisp programs; use bookmark-save
  1255. instead."
  1256.   (interactive)
  1257.   (bookmark-maybe-load-default-file)
  1258.   (bookmark-save t))
  1259.  
  1260.  
  1261. ;;;###autoload
  1262. (defun bookmark-save (&optional parg file) 
  1263.   "Save currently defined bookmarks.
  1264. Saves by default in the file defined by the variable
  1265. `bookmark-default-file'.  With a prefix arg, save it in file FILE
  1266. \(second argument\).
  1267.  
  1268. If you are calling this from Lisp, the two arguments are PREFIX-ARG
  1269. and FILE, and if you just want it to write to the default file, then
  1270. pass no arguments.  Or pass in nil and FILE, and it will save in FILE
  1271. instead.  If you pass in one argument, and it is non-nil, then the
  1272. user will be interactively queried for a file to save in.
  1273.  
  1274. When you want to load in the bookmarks from a file, use
  1275. \`bookmark-load\', \\[bookmark-load].  That function will prompt you
  1276. for a file, defaulting to the file defined by variable
  1277. `bookmark-default-file'."
  1278.   (interactive "P")
  1279.   (bookmark-maybe-load-default-file)
  1280.   (cond
  1281.    ((and (null parg) (null file))
  1282.     ;;whether interactive or not, write to default file
  1283.     (bookmark-write-file bookmark-default-file))
  1284.    ((and (null parg) file)
  1285.     ;;whether interactive or not, write to given file
  1286.     (bookmark-write-file file))
  1287.    ((and parg (not file))
  1288.     ;;have been called interactively w/ prefix arg
  1289.     (let ((file (read-file-name "File to save bookmarks in: ")))
  1290.       (bookmark-write-file file)))
  1291.    (t ; someone called us with prefix-arg *and* a file, so just write to file
  1292.     (bookmark-write-file file)))
  1293.   ;; signal that we have synced the bookmark file by setting this to
  1294.   ;; 0.  If there was an error at any point before, it will not get
  1295.   ;; set, which is what we want.
  1296.   (setq bookmark-alist-modification-count 0))
  1297.  
  1298.  
  1299.  
  1300. (defun bookmark-write-file (file)
  1301.   (save-excursion
  1302.     (save-window-excursion
  1303.       (if (>= baud-rate 9600)
  1304.           (message (format "Saving bookmarks to file %s..." file)))
  1305.       (set-buffer (let ((enable-local-variables nil))
  1306.                     (find-file-noselect file)))
  1307.       (goto-char (point-min))
  1308.       (delete-region (point-min) (point-max))
  1309.       (bookmark-insert-file-format-version-stamp)
  1310.       (pp bookmark-alist (current-buffer))
  1311.       (let ((version-control
  1312.              (cond
  1313.               ((null bookmark-version-control) nil)
  1314.               ((eq 'never bookmark-version-control) 'never)
  1315.               ((eq 'nospecial bookmark-version-control) version-control)
  1316.               (t
  1317.                t))))
  1318.         (write-file file)
  1319.         (kill-buffer (current-buffer))
  1320.         (if (>= baud-rate 9600)
  1321.             (message (format "Saving bookmarks to file %s... done." file)))
  1322.         ))))
  1323.  
  1324.  
  1325. ;;;###autoload
  1326. (defun bookmark-load (file &optional revert no-msg)
  1327.   "Load bookmarks from FILE (which must be in bookmark format).
  1328. Appends loaded bookmarks to the front of the list of bookmarks.  If
  1329. optional second argument REVERT is non-nil, existing bookmarks are
  1330. destroyed.  Optional third arg NO-MSG means don't display any messages
  1331. while loading.
  1332.  
  1333. If you load a file that doesn't contain a proper bookmark alist, you
  1334. will corrupt Emacs's bookmark list.  Generally, you should only load
  1335. in files that were created with the bookmark functions in the first
  1336. place.  Your own personal bookmark file, `~/.emacs.bmk', is
  1337. maintained automatically by Emacs; you shouldn't need to load it
  1338. explicitly."
  1339.   (interactive
  1340.    (list (read-file-name
  1341.           (format "Load bookmarks from: (%s) "
  1342.                   bookmark-default-file)        
  1343.           ;;Default might not be used often,
  1344.           ;;but there's no better default, and
  1345.           ;;I guess it's better than none at all.
  1346.           "~/" bookmark-default-file 'confirm)))
  1347.   (setq file (expand-file-name file))
  1348.   (if (file-readable-p file)
  1349.       (save-excursion
  1350.         (save-window-excursion
  1351.           (if (and (null no-msg) (>= baud-rate 9600))
  1352.               (message (format "Loading bookmarks from %s..." file)))
  1353.           (set-buffer (let ((enable-local-variables nil))
  1354.                         (find-file-noselect file)))
  1355.           (goto-char (point-min))
  1356.           (bookmark-maybe-upgrade-file-format)
  1357.           (let ((blist (bookmark-alist-from-buffer)))
  1358.             (if (listp blist)
  1359.                 (progn
  1360.                   (if (not revert)
  1361.                       (setq bookmark-alist-modification-count
  1362.                             (1+ bookmark-alist-modification-count))
  1363.                     (setq bookmark-alist-modification-count 0))
  1364.                   (setq bookmark-alist
  1365.                         (append blist (if (not revert) bookmark-alist)))
  1366.                   (bookmark-bmenu-surreptitiously-rebuild-list)) 
  1367.               (error (format "Invalid bookmark list in %s." file))))
  1368.           (kill-buffer (current-buffer)))
  1369.     (if (and (null no-msg) (>= baud-rate 9600))
  1370.             (message (format "Loading bookmarks from %s... done" file))))
  1371.     (error (format "Cannot read bookmark file %s." file))))
  1372.  
  1373.  
  1374.  
  1375. ;;; Code supporting the dired-like bookmark menu.  Prefix is
  1376. ;;; "bookmark-bmenu" for "buffer-menu":
  1377.  
  1378.  
  1379. (defvar bookmark-bmenu-bookmark-column nil)
  1380.  
  1381.  
  1382. (defvar bookmark-bmenu-hidden-bookmarks ())
  1383.  
  1384.  
  1385. (defvar bookmark-bmenu-mode-map nil)
  1386.  
  1387.  
  1388. (if bookmark-bmenu-mode-map
  1389.     nil
  1390.   (setq bookmark-bmenu-mode-map (make-keymap))
  1391.   (suppress-keymap bookmark-bmenu-mode-map t)
  1392.   (define-key bookmark-bmenu-mode-map "q" 'bookmark-bmenu-quit)
  1393.   (define-key bookmark-bmenu-mode-map "v" 'bookmark-bmenu-select)
  1394.   (define-key bookmark-bmenu-mode-map "w" 'bookmark-bmenu-locate)
  1395.   (define-key bookmark-bmenu-mode-map "2" 'bookmark-bmenu-2-window)
  1396.   (define-key bookmark-bmenu-mode-map "1" 'bookmark-bmenu-1-window)
  1397.   (define-key bookmark-bmenu-mode-map "j" 'bookmark-bmenu-this-window)
  1398.   (define-key bookmark-bmenu-mode-map "f" 'bookmark-bmenu-this-window)
  1399.   (define-key bookmark-bmenu-mode-map "o" 'bookmark-bmenu-other-window)
  1400.   (define-key bookmark-bmenu-mode-map "\C-o" 'bookmark-bmenu-switch-other-window)
  1401.   (define-key bookmark-bmenu-mode-map "s" 'bookmark-bmenu-save)
  1402.   (define-key bookmark-bmenu-mode-map "k" 'bookmark-bmenu-delete)
  1403.   (define-key bookmark-bmenu-mode-map "\C-d" 'bookmark-bmenu-delete-backwards)
  1404.   (define-key bookmark-bmenu-mode-map "x" 'bookmark-bmenu-execute-deletions)
  1405.   (define-key bookmark-bmenu-mode-map "\C-k" 'bookmark-bmenu-delete)
  1406.   (define-key bookmark-bmenu-mode-map "d" 'bookmark-bmenu-delete)
  1407.   (define-key bookmark-bmenu-mode-map " " 'next-line)
  1408.   (define-key bookmark-bmenu-mode-map "n" 'next-line)
  1409.   (define-key bookmark-bmenu-mode-map "p" 'previous-line)
  1410.   (define-key bookmark-bmenu-mode-map "\177" 'bookmark-bmenu-backup-unmark)
  1411.   (define-key bookmark-bmenu-mode-map "?" 'describe-mode)
  1412.   (define-key bookmark-bmenu-mode-map "u" 'bookmark-bmenu-unmark)
  1413.   (define-key bookmark-bmenu-mode-map "m" 'bookmark-bmenu-mark)
  1414.   (define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load) 
  1415.   (define-key bookmark-bmenu-mode-map "r" 'bookmark-bmenu-rename)
  1416.   (define-key bookmark-bmenu-mode-map "t" 'bookmark-bmenu-toggle-filenames)
  1417.   (define-key bookmark-bmenu-mode-map "a" 'bookmark-bmenu-show-annotation)
  1418.   (define-key bookmark-bmenu-mode-map "A" 'bookmark-bmenu-show-all-annotations)
  1419.   (define-key bookmark-bmenu-mode-map "e" 'bookmark-bmenu-edit-annotation))
  1420.  
  1421.   
  1422.  
  1423. ;; Bookmark Buffer Menu mode is suitable only for specially formatted
  1424. ;; data.
  1425. (put 'bookmark-bmenu-mode 'mode-class 'special)
  1426.  
  1427.  
  1428. ;; todo: need to display whether or not bookmark exists as a buffer in
  1429. ;; flag column. 
  1430.  
  1431. ;; Format:
  1432. ;; FLAGS  BOOKMARK [ LOCATION ]
  1433.  
  1434.  
  1435. (defun bookmark-bmenu-surreptitiously-rebuild-list ()
  1436.   "Rebuild the Bookmark List if it exists.
  1437. Don't affect the buffer ring order."
  1438.   (if (get-buffer "*Bookmark List*")
  1439.       (save-excursion
  1440.         (save-window-excursion 
  1441.           (bookmark-bmenu-list)))))
  1442.  
  1443.  
  1444. ;;;###autoload
  1445. (defun bookmark-bmenu-list ()
  1446.   "Display a list of existing bookmarks.
  1447. The list is displayed in a buffer named `*Bookmark List*'.
  1448. The leftmost column displays a D if the bookmark is flagged for
  1449. deletion, or > if it is flagged for displaying."
  1450.   (interactive)
  1451.   (bookmark-maybe-load-default-file)
  1452.   (if (interactive-p)
  1453.       (switch-to-buffer (get-buffer-create "*Bookmark List*"))
  1454.     (set-buffer (get-buffer-create "*Bookmark List*")))
  1455.   (let ((buffer-read-only nil))
  1456.     (delete-region (point-max) (point-min))
  1457.     (goto-char (point-min)) ;sure are playing it safe...
  1458.     (insert "% Bookmark\n- --------\n")
  1459.     (bookmark-maybe-sort-alist)
  1460.     (mapcar
  1461.      (lambda (full-record)
  1462.        ;; if a bookmark has an annotation, preceed it with a "*"
  1463.        ;; in the list of bookmarks.
  1464.        (let ((annotation (bookmark-get-annotation
  1465.                           (bookmark-name-from-full-record full-record))))
  1466.          (if (and (not (eq annotation nil))
  1467.                   (not (string-equal annotation "")))
  1468.              (insert " *")
  1469.            (insert "  "))
  1470.          (insert (concat (bookmark-name-from-full-record full-record) "\n"))))
  1471.      bookmark-alist))
  1472.   (goto-char (point-min))
  1473.   (forward-line 2)
  1474.   (bookmark-bmenu-mode)
  1475.   (if bookmark-bmenu-toggle-filenames
  1476.       (bookmark-bmenu-toggle-filenames t)))
  1477.  
  1478. ;;;###autoload
  1479. (defalias 'list-bookmarks 'bookmark-bmenu-list)
  1480. ;;;###autoload
  1481. (defalias 'edit-bookmarks 'bookmark-bmenu-list)
  1482.  
  1483.  
  1484.  
  1485. (defun bookmark-bmenu-mode ()
  1486.   "Major mode for editing a list of bookmarks.
  1487. Each line describes one of the bookmarks in Emacs.
  1488. Letters do not insert themselves; instead, they are commands.
  1489. Bookmark names preceeded by a \"*\" have annotations.
  1490. \\<bookmark-bmenu-mode-map>
  1491. \\[bookmark-bmenu-mark] -- mark bookmark to be displayed.
  1492. \\[bookmark-bmenu-select] -- select bookmark of line point is on.
  1493.   Also show bookmarks marked using m in other windows.
  1494. \\[bookmark-bmenu-toggle-filenames] -- toggle displaying of filenames (they may obscure long bookmark names).
  1495. \\[bookmark-bmenu-locate] -- display (in minibuffer) location of this bookmark.
  1496. \\[bookmark-bmenu-1-window] -- select this bookmark in full-frame window.
  1497. \\[bookmark-bmenu-2-window] -- select this bookmark in one window,
  1498.   together with bookmark selected before this one in another window.
  1499. \\[bookmark-bmenu-this-window] -- select this bookmark in place of the bookmark menu buffer.
  1500. \\[bookmark-bmenu-other-window] -- select this bookmark in another window,
  1501.   so the bookmark menu bookmark remains visible in its window.
  1502. \\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
  1503. \\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).   
  1504. \\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
  1505. \\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up. 
  1506. \\[bookmark-bmenu-execute-deletions] -- delete marked bookmarks.
  1507. \\[bookmark-bmenu-save] -- save the current bookmark list in the default file.
  1508.   With a prefix arg, prompts for a file to save in.
  1509. \\[bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
  1510. \\[bookmark-bmenu-unmark] -- remove all kinds of marks from current line.
  1511.   With prefix argument, also move up one line.
  1512. \\[bookmark-bmenu-backup-unmark] -- back up a line and remove marks.
  1513. \\[bookmark-bmenu-show-annotation] -- show the annotation, if it exists, for the current bookmark
  1514.   in another buffer.
  1515. \\[bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer.
  1516. \\[bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark."
  1517.   (kill-all-local-variables)
  1518.   (use-local-map bookmark-bmenu-mode-map)
  1519.   (setq truncate-lines t)
  1520.   (setq buffer-read-only t)
  1521.   (setq major-mode 'bookmark-bmenu-mode)
  1522.   (setq mode-name "Bookmark Menu")
  1523.   (run-hooks 'bookmark-bmenu-mode-hook))
  1524.  
  1525.  
  1526. (defun bookmark-bmenu-toggle-filenames (&optional show)
  1527.   "Toggle whether filenames are shown in the bookmark list.
  1528. Optional argument SHOW means show them unconditionally."
  1529.   (interactive)
  1530.   (cond
  1531.    (show
  1532.     (setq bookmark-bmenu-toggle-filenames nil)
  1533.     (bookmark-bmenu-show-filenames)
  1534.     (setq bookmark-bmenu-toggle-filenames t))
  1535.    (bookmark-bmenu-toggle-filenames
  1536.     (bookmark-bmenu-hide-filenames)
  1537.     (setq bookmark-bmenu-toggle-filenames nil))
  1538.    (t
  1539.     (bookmark-bmenu-show-filenames)
  1540.     (setq bookmark-bmenu-toggle-filenames t))))
  1541.  
  1542.  
  1543. (defun bookmark-bmenu-show-filenames (&optional force)
  1544.   (if (and (not force) bookmark-bmenu-toggle-filenames)
  1545.       nil ;already shown, so do nothing
  1546.     (save-excursion
  1547.       (save-window-excursion
  1548.         (goto-char (point-min))
  1549.         (forward-line 2)
  1550.         (setq bookmark-bmenu-hidden-bookmarks ())
  1551.         (let ((buffer-read-only nil))
  1552.           (while (< (point) (point-max))
  1553.             (let ((bmrk (bookmark-bmenu-bookmark)))
  1554.               (setq bookmark-bmenu-hidden-bookmarks
  1555.                     (cons bmrk bookmark-bmenu-hidden-bookmarks))
  1556.               (move-to-column bookmark-bmenu-file-column t)
  1557.               (delete-region (point) (progn (end-of-line) (point)))
  1558.               (insert "  ")
  1559.               ;; Pass the NO-HISTORY arg:
  1560.               (bookmark-insert-location bmrk t)
  1561.               (forward-line 1))))))))
  1562.  
  1563.  
  1564. (defun bookmark-bmenu-hide-filenames (&optional force)
  1565.   (if (and (not force) bookmark-bmenu-toggle-filenames)
  1566.       ;; nothing to hide if above is nil
  1567.       (save-excursion
  1568.         (save-window-excursion
  1569.           (goto-char (point-min))
  1570.           (forward-line 2)
  1571.           (setq bookmark-bmenu-hidden-bookmarks
  1572.                 (nreverse bookmark-bmenu-hidden-bookmarks))
  1573.           (save-excursion
  1574.             (goto-char (point-min))
  1575.             (search-forward "Bookmark")
  1576.             (backward-word 1)
  1577.             (setq bookmark-bmenu-bookmark-column (current-column)))
  1578.           (save-excursion
  1579.             (let ((buffer-read-only nil))
  1580.               (while bookmark-bmenu-hidden-bookmarks
  1581.                 (move-to-column bookmark-bmenu-bookmark-column t)
  1582.                 (bookmark-kill-line)
  1583.                 (insert (car bookmark-bmenu-hidden-bookmarks))
  1584.                 (setq bookmark-bmenu-hidden-bookmarks
  1585.                       (cdr bookmark-bmenu-hidden-bookmarks))
  1586.                 (forward-line 1))))))))
  1587.  
  1588.  
  1589. ;; if you look at this next function from far away, it resembles a
  1590. ;; gun.  But only with this comment above... 
  1591. (defun bookmark-bmenu-check-position ()
  1592.   ;; Returns t if on a line with a bookmark.
  1593.   ;; Otherwise, repositions and returns t.
  1594.   ;; written by David Hughes <djh@harston.cv.com>
  1595.   ;; Mucho thanks, David!  -karl
  1596.   (cond ((< (count-lines (point-min) (point)) 2)
  1597.          (goto-char (point-min))
  1598.          (forward-line 2)
  1599.          t)
  1600.         ((and (bolp) (eobp))
  1601.          (beginning-of-line 0)
  1602.          t)
  1603.         (t
  1604.          t)))
  1605.  
  1606.  
  1607. (defun bookmark-bmenu-bookmark ()
  1608.   ;; return a string which is bookmark of this line.
  1609.   (if (bookmark-bmenu-check-position)
  1610.       (save-excursion
  1611.         (save-window-excursion
  1612.           (goto-char (point-min))
  1613.           (search-forward "Bookmark")
  1614.           (backward-word 1)
  1615.           (setq bookmark-bmenu-bookmark-column (current-column)))))
  1616.   (if bookmark-bmenu-toggle-filenames
  1617.       (bookmark-bmenu-hide-filenames))
  1618.   (save-excursion
  1619.     (save-window-excursion
  1620.       (beginning-of-line)
  1621.       (forward-char bookmark-bmenu-bookmark-column)
  1622.       (prog1
  1623.           (buffer-substring (point)
  1624.                             (progn 
  1625.                               (end-of-line)
  1626.                               (point)))
  1627.         ;; well, this is certainly crystal-clear:
  1628.         (if bookmark-bmenu-toggle-filenames
  1629.             (bookmark-bmenu-toggle-filenames t))))))
  1630.  
  1631.  
  1632. (defun bookmark-show-annotation (bookmark)
  1633.   "Display the annotation for bookmark named BOOKMARK in a buffer,
  1634. if an annotation exists."
  1635.   (let ((annotation (bookmark-get-annotation bookmark)))
  1636.     (if (and (not (eq annotation nil))
  1637.          (not (string-equal annotation "")))
  1638.     (progn
  1639.           (save-excursion
  1640.         (let ((old-buf (current-buffer)))
  1641.           (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
  1642.           (delete-region (point-min) (point-max))
  1643.           ; (insert (concat "Annotation for bookmark '" bookmark "':\n\n"))
  1644.           (insert annotation)
  1645.           (goto-char (point-min))
  1646.           (pop-to-buffer old-buf)))))))
  1647.  
  1648.  
  1649. (defun bookmark-show-all-annotations ()
  1650.   "Display the annotations for all bookmarks in a buffer."
  1651.   (let ((old-buf (current-buffer)))
  1652.     (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
  1653.     (delete-region (point-min) (point-max))
  1654.     (mapcar
  1655.      (lambda (full-record)
  1656.        (let* ((name (bookmark-name-from-full-record full-record))
  1657.               (ann  (bookmark-get-annotation name)))
  1658.          (insert (concat name ":\n"))
  1659.          (if (and (not (eq ann nil)) (not (string-equal ann "")))
  1660.              ;; insert the annotation, indented by 4 spaces.
  1661.              (progn
  1662.                (save-excursion (insert ann))
  1663.                (while (< (point) (point-max))
  1664.                  (beginning-of-line) ; paranoia
  1665.                  (insert "    ")
  1666.                  (forward-line)
  1667.                  (end-of-line))))))
  1668.      bookmark-alist)
  1669.     (goto-char (point-min))
  1670.     (pop-to-buffer old-buf)))
  1671.  
  1672.  
  1673. (defun bookmark-bmenu-mark ()
  1674.   "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select] command."
  1675.   (interactive)
  1676.   (beginning-of-line)
  1677.   (if (bookmark-bmenu-check-position)
  1678.       (let ((buffer-read-only nil))
  1679.         (delete-char 1)
  1680.         (insert ?>)
  1681.         (forward-line 1))))
  1682.  
  1683.  
  1684. (defun bookmark-bmenu-select ()
  1685.   "Select this line's bookmark; also display bookmarks marked with `>'.
  1686. You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mark] command."
  1687.   (interactive)
  1688.   (if (bookmark-bmenu-check-position)
  1689.       (let ((bmrk (bookmark-bmenu-bookmark))
  1690.             (menu (current-buffer))          
  1691.             (others ())
  1692.             tem)
  1693.         (goto-char (point-min))
  1694.         (while (re-search-forward "^>" nil t)
  1695.           (setq tem (bookmark-bmenu-bookmark))
  1696.           (let ((buffer-read-only nil))
  1697.             (delete-char -1)
  1698.             (insert ?\ ))
  1699.           (or (string-equal tem bmrk) 
  1700.               (member tem others) 
  1701.               (setq others (cons tem others))))
  1702.         (setq others (nreverse others)
  1703.               tem (/ (1- (frame-height)) (1+ (length others))))
  1704.         (delete-other-windows)
  1705.         (bookmark-jump bmrk)
  1706.         (bury-buffer menu)
  1707.         (if others
  1708.             (while others
  1709.               (split-window nil tem)
  1710.               (other-window 1)
  1711.               (bookmark-jump (car others))
  1712.               (setq others (cdr others)))
  1713.           (other-window 1)))))
  1714.  
  1715.  
  1716. (defun bookmark-bmenu-save (parg)
  1717.   "Save the current list into a bookmark file.
  1718. With a prefix arg, prompts for a file to save them in."
  1719.   (interactive "P")
  1720.   (save-excursion
  1721.     (save-window-excursion
  1722.       (bookmark-save parg))))
  1723.  
  1724.  
  1725. (defun bookmark-bmenu-load ()
  1726.   "Load the bookmark file and rebuild the bookmark menu-buffer."
  1727.   (interactive)
  1728.   (if (bookmark-bmenu-check-position)
  1729.       (save-excursion
  1730.         (save-window-excursion
  1731.           ;; This will call `bookmark-bmenu-list'
  1732.           (call-interactively 'bookmark-load)))))
  1733.  
  1734.  
  1735. (defun bookmark-bmenu-1-window ()
  1736.   "Select this line's bookmark, alone, in full frame."
  1737.   (interactive)
  1738.   (if (bookmark-bmenu-check-position)
  1739.       (progn
  1740.         (bookmark-jump (bookmark-bmenu-bookmark))
  1741.         (bury-buffer (other-buffer))
  1742.         (delete-other-windows))))
  1743.  
  1744.  
  1745. (defun bookmark-bmenu-2-window ()
  1746.   "Select this line's bookmark, with previous buffer in second window."
  1747.   (interactive)
  1748.   (if (bookmark-bmenu-check-position)
  1749.       (let ((bmrk (bookmark-bmenu-bookmark))
  1750.             (menu (current-buffer))
  1751.             (pop-up-windows t))
  1752.         (delete-other-windows)
  1753.         (switch-to-buffer (other-buffer))
  1754.     (let* ((pair (bookmark-jump-noselect bmrk))
  1755.                (buff (car pair))
  1756.                (pos  (cdr pair)))
  1757.           (pop-to-buffer buff)
  1758.           (goto-char pos))
  1759.         (bury-buffer menu))))
  1760.  
  1761.  
  1762. (defun bookmark-bmenu-this-window ()
  1763.   "Select this line's bookmark in this window."
  1764.   (interactive)
  1765.   (if (bookmark-bmenu-check-position)
  1766.       (bookmark-jump (bookmark-bmenu-bookmark))))
  1767.  
  1768.  
  1769. (defun bookmark-bmenu-other-window ()
  1770.   "Select this line's bookmark in other window, leaving bookmark menu visible."
  1771.   (interactive)
  1772.   (let ((bookmark (bookmark-bmenu-bookmark)))
  1773.     (if (bookmark-bmenu-check-position)
  1774.     (let* ((pair (bookmark-jump-noselect bookmark))
  1775.                (buff (car pair))
  1776.                (pos  (cdr pair)))
  1777.       (switch-to-buffer-other-window buff)
  1778.           (goto-char pos)
  1779.           (set-window-point (get-buffer-window buff) pos)
  1780.       (bookmark-show-annotation bookmark)))))
  1781.  
  1782.  
  1783. (defun bookmark-bmenu-switch-other-window ()
  1784.   "Make the other window select this line's bookmark.
  1785. The current window remains selected."
  1786.   (interactive)
  1787.   (let ((bookmark (bookmark-bmenu-bookmark)))
  1788.     (if (bookmark-bmenu-check-position)
  1789.     (let* ((pair (bookmark-jump-noselect bookmark))
  1790.                (buff (car pair))
  1791.                (pos  (cdr pair)))
  1792.       (display-buffer buff)
  1793.           (let ((o-buffer (current-buffer)))
  1794.             ;; save-excursion won't do
  1795.             (set-buffer buff)
  1796.             (goto-char pos)
  1797.             (set-window-point (get-buffer-window buff) pos)
  1798.             (set-buffer o-buffer))
  1799.       (bookmark-show-annotation bookmark)))))
  1800.  
  1801.  
  1802. (defun bookmark-bmenu-show-annotation ()
  1803.   "Show the annotation for the current bookmark in another window."
  1804.   (interactive)
  1805.   (let ((bookmark (bookmark-bmenu-bookmark)))
  1806.     (if (bookmark-bmenu-check-position)
  1807.     (bookmark-show-annotation bookmark))))
  1808.  
  1809.  
  1810. (defun bookmark-bmenu-show-all-annotations ()
  1811.   "Show the annotation for all bookmarks in another window."
  1812.   (interactive)
  1813.   (bookmark-show-all-annotations))
  1814.  
  1815.  
  1816. (defun bookmark-bmenu-edit-annotation ()
  1817.   "Edit the annotation for the current bookmark in another window."
  1818.   (interactive)
  1819.   (let ((bookmark (bookmark-bmenu-bookmark)))
  1820.     (if (bookmark-bmenu-check-position)
  1821.     (bookmark-edit-annotation bookmark))))
  1822.  
  1823.  
  1824. (defun bookmark-bmenu-quit ()
  1825.   "Quit the bookmark menu."
  1826.   (interactive)
  1827.   (let ((buffer (current-buffer)))
  1828.     (switch-to-buffer (other-buffer))
  1829.     (bury-buffer buffer)))
  1830.  
  1831.  
  1832. (defun bookmark-bmenu-unmark (&optional backup)
  1833.   "Cancel all requested operations on bookmark on this line and move down.
  1834. Optional BACKUP means move up."
  1835.   (interactive "P")
  1836.   (beginning-of-line)
  1837.   (if (bookmark-bmenu-check-position)
  1838.       (progn
  1839.         (let ((buffer-read-only nil))
  1840.           (delete-char 1)
  1841.           ;; any flags to reset according to circumstances?  How about a
  1842.           ;; flag indicating whether this bookmark is being visited?
  1843.           ;; well, we don't have this now, so maybe later.
  1844.           (insert " "))
  1845.         (forward-line (if backup -1 1)))))
  1846.  
  1847.  
  1848. (defun bookmark-bmenu-backup-unmark ()
  1849.   "Move up and cancel all requested operations on bookmark on line above."
  1850.   (interactive)
  1851.   (forward-line -1)
  1852.   (if (bookmark-bmenu-check-position)
  1853.       (progn
  1854.         (bookmark-bmenu-unmark)
  1855.         (forward-line -1))))
  1856.  
  1857.  
  1858. (defun bookmark-bmenu-delete ()
  1859.   "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command."
  1860.   (interactive)
  1861.   (beginning-of-line)
  1862.   (if (bookmark-bmenu-check-position)
  1863.       (let ((buffer-read-only nil))
  1864.         (delete-char 1)
  1865.         (insert ?D)
  1866.         (forward-line 1))))
  1867.  
  1868.  
  1869. (defun bookmark-bmenu-delete-backwards ()
  1870.   "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command
  1871. and then move up one line"
  1872.   (interactive)
  1873.   (bookmark-bmenu-delete)
  1874.   (forward-line -2)
  1875.   (if (bookmark-bmenu-check-position)
  1876.       (forward-line 1)))
  1877.  
  1878.  
  1879. (defun bookmark-bmenu-execute-deletions ()
  1880.   "Delete bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
  1881.   (interactive)
  1882.   (let ((hide-em bookmark-bmenu-toggle-filenames)
  1883.         (o-point  (point))
  1884.         (o-str    (save-excursion
  1885.                     (beginning-of-line)
  1886.                     (if (looking-at "^D")
  1887.                         nil
  1888.                       (buffer-substring
  1889.                        (point)
  1890.                        (progn (end-of-line) (point))))))
  1891.         (o-col     (current-column)))
  1892.     (if hide-em (bookmark-bmenu-hide-filenames))
  1893.     (setq bookmark-bmenu-toggle-filenames nil)
  1894.     (goto-char (point-min))
  1895.     (forward-line 1)
  1896.     (while (re-search-forward "^D" (point-max) t)
  1897.       (bookmark-delete (bookmark-bmenu-bookmark) t)) ; pass BATCH arg
  1898.     (bookmark-bmenu-list)
  1899.     (setq bookmark-bmenu-toggle-filenames hide-em)
  1900.     (if bookmark-bmenu-toggle-filenames
  1901.         (bookmark-bmenu-toggle-filenames t))
  1902.     (if o-str
  1903.         (progn
  1904.           (goto-char (point-min))
  1905.           (search-forward o-str)
  1906.           (beginning-of-line)
  1907.           (forward-char o-col))
  1908.       (goto-char o-point))
  1909.     (beginning-of-line)
  1910.     (setq bookmark-alist-modification-count
  1911.           (1+ bookmark-alist-modification-count))
  1912.     (if (bookmark-time-to-save-p)
  1913.         (bookmark-save))))
  1914.  
  1915.  
  1916. (defun bookmark-bmenu-rename ()
  1917.   "Rename bookmark on current line.  Prompts for a new name."
  1918.   (interactive)
  1919.   (if (bookmark-bmenu-check-position)
  1920.       (let ((bmrk (bookmark-bmenu-bookmark))
  1921.             (thispoint (point)))
  1922.         (bookmark-rename bmrk)
  1923.         (bookmark-bmenu-list)
  1924.         (goto-char thispoint))))
  1925.  
  1926.  
  1927. (defun bookmark-bmenu-locate ()
  1928.   "Display location of this bookmark.  Displays in the minibuffer."
  1929.   (interactive)
  1930.   (if (bookmark-bmenu-check-position)
  1931.       (let ((bmrk (bookmark-bmenu-bookmark)))
  1932.         (message (bookmark-location bmrk)))))
  1933.  
  1934.  
  1935.  
  1936. ;;; Menu bar stuff.  Prefix is "bookmark-menu".
  1937.  
  1938. (defun bookmark-menu-build-paned-menu (name entries)
  1939.   "Build a multi-paned menu named NAME from the strings in ENTRIES.
  1940. That is, ENTRIES is a list of strings which appear as the choices
  1941. in the menu.  The number of panes depends on the number of entries.
  1942. The visible entries are truncated to `bookmark-menu-length', but the
  1943. strings returned are not."
  1944.   (let* ((f-height (/ (frame-height) 2))
  1945.          (pane-list
  1946.           (let (temp-pane-list
  1947.                 (iter 0))
  1948.             (while entries
  1949.               (let (lst
  1950.                     (count 0))
  1951.                 (while (and (< count f-height) entries)
  1952.                   (let ((str (car entries)))
  1953.                     (setq lst (cons
  1954.                                (cons
  1955.                                 (if (> (length str) bookmark-menu-length)
  1956.                                     (substring str 0 bookmark-menu-length)
  1957.                                   str)
  1958.                                 str)
  1959.                                lst))
  1960.                     (setq entries (cdr entries))
  1961.                     (setq count (1+ count))))
  1962.                 (setq iter (1+ iter))
  1963.                 (setq
  1964.                  temp-pane-list
  1965.                  (cons
  1966.                   (cons
  1967.                    (format "-*- %s (%d) -*-" name iter)
  1968.                    (nreverse lst))
  1969.                   temp-pane-list))))
  1970.             (nreverse temp-pane-list))))
  1971.  
  1972.     ;; Return the menu:
  1973.     (cons (concat "-*- " name " -*-") pane-list)))
  1974.  
  1975.  
  1976. (defun bookmark-build-xemacs-menu (name entries function)
  1977.   "Build a menu named NAME from the strings in ENTRIES.
  1978. That is, ENTRIES is a list of strings that appear as the choices
  1979. in the menu.
  1980. The visible entries are truncated to `bookmark-menu-length', but the
  1981. strings returned are not."
  1982.   (let* (lst 
  1983.      (pane-list
  1984.       (progn
  1985.         (while entries
  1986.           (let ((str (car entries)))
  1987.         (setq lst (cons
  1988.                (vector
  1989.                 (if (> (length str) bookmark-menu-length)
  1990.                 (substring str 0 bookmark-menu-length)
  1991.                   str)
  1992.                 (list function str)
  1993.                 t)
  1994.                lst))
  1995.         (setq entries (cdr entries))))
  1996.         (nreverse lst))))
  1997.  
  1998.     ;; Return the menu:
  1999.     (append (if popup-menu-titles (list (concat "-*- " name " -*-")))
  2000.          pane-list)))
  2001.  
  2002.  
  2003. (defun bookmark-menu-popup-paned-menu (event name entries)
  2004.   "Pop up multi-paned menu at EVENT, return string chosen from ENTRIES.
  2005. That is, ENTRIES is a list of strings which appear as the choices
  2006. in the menu.
  2007. The number of panes depends on the number of entries."
  2008.   (interactive "e")
  2009.   (x-popup-menu event (bookmark-menu-build-paned-menu name entries)))
  2010.  
  2011.  
  2012. (defun bookmark-menu-popup-paned-bookmark-menu (event name)
  2013.   "Pop up menu of bookmarks, return chosen bookmark.
  2014. Pop up at EVENT, menu's name is NAME.
  2015. The number of panes depends on the number of bookmarks."
  2016.   (bookmark-menu-popup-paned-menu event name (bookmark-all-names)))
  2017.  
  2018.  
  2019. (defun bookmark-popup-menu-and-apply-function (func-sym menu-label event)
  2020.   ;; help function for making menus that need to apply a bookmark
  2021.   ;; function to a string.
  2022.   (if bookmark-xemacsp
  2023.       (popup-menu (bookmark-build-xemacs-menu
  2024.             menu-label (bookmark-all-names) func-sym))
  2025.     (let* ((choice (bookmark-menu-popup-paned-bookmark-menu
  2026.              event menu-label)))
  2027.       (if choice (apply func-sym (list choice))))))
  2028.  
  2029.  
  2030. ;;;###autoload
  2031. (defun bookmark-menu-insert (event)
  2032.   "Insert the text of the file pointed to by bookmark BOOKMARK.  
  2033. You may have a problem using this function if the value of variable
  2034. `bookmark-alist' is nil.  If that happens, you need to load in some
  2035. bookmarks.  See help on function `bookmark-load' for more about
  2036. this.
  2037.  
  2038. Warning: this function only takes an EVENT as argument.  Use the
  2039. corresponding bookmark function from Lisp \(the one without the
  2040. \"-menu-\" in its name\)."
  2041.   (interactive "e")
  2042.   (bookmark-popup-menu-and-apply-function
  2043.    'bookmark-insert "Insert Bookmark Contents" event))
  2044.  
  2045.  
  2046. ;;;###autoload
  2047. (defun bookmark-menu-jump (event)
  2048.   "Jump to bookmark BOOKMARK (a point in some file).  
  2049. You may have a problem using this function if the value of variable
  2050. `bookmark-alist' is nil.  If that happens, you need to load in some
  2051. bookmarks.  See help on function `bookmark-load' for more about
  2052. this.
  2053.  
  2054. Warning: this function only takes an EVENT as argument.  Use the
  2055. corresponding bookmark function from Lisp \(the one without the
  2056. \"-menu-\" in its name\)."
  2057.   (interactive "e")
  2058.   (bookmark-popup-menu-and-apply-function
  2059.    'bookmark-jump "Jump to Bookmark" event))
  2060.  
  2061.  
  2062. ;;;###autoload
  2063. (defun bookmark-menu-locate (event)
  2064.   "Insert the name of the file associated with BOOKMARK. 
  2065. \(This is not the same as the contents of that file\).
  2066.  
  2067. Warning: this function only takes an EVENT as argument.  Use the
  2068. corresponding bookmark function from Lisp \(the one without the
  2069. \"-menu-\" in its name\)."
  2070.   (interactive "e")
  2071.   (bookmark-popup-menu-and-apply-function
  2072.    'bookmark-insert-location "Insert Bookmark Location" event))
  2073.  
  2074.  
  2075. ;;;###autoload
  2076. (defun bookmark-menu-rename (event)
  2077.   "Change the name of OLD-BOOKMARK to NEWNAME.  
  2078. If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
  2079. If called from menubar, OLD-BOOKMARK is selected from a menu, and
  2080. prompts for NEWNAME. 
  2081. If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
  2082. passed as an argument.  If called with two strings, then no prompting
  2083. is done.  You must pass at least OLD-BOOKMARK when calling from Lisp.
  2084.  
  2085. While you are entering the new name, consecutive C-w's insert
  2086. consectutive words from the text of the buffer into the new bookmark
  2087. name.
  2088.  
  2089. Warning: this function only takes an EVENT as argument.  Use the
  2090. corresponding bookmark function from Lisp \(the one without the
  2091. \"-menu-\" in its name\)."
  2092.   (interactive "e")
  2093.   (bookmark-popup-menu-and-apply-function
  2094.    'bookmark-rename "Rename Bookmark" event))
  2095.  
  2096.  
  2097. ;;;###autoload
  2098. (defun bookmark-menu-delete (event)
  2099.   "Delete the bookmark named NAME from the bookmark list.  
  2100. Removes only the first instance of a bookmark with that name.  If
  2101. there are one or more other bookmarks with the same name, they will
  2102. not be deleted.  Defaults to the \"current\" bookmark \(that is, the
  2103. one most recently used in this file, if any\).
  2104.  
  2105. Warning: this function only takes an EVENT as argument.  Use the
  2106. corresponding bookmark function from Lisp \(the one without the
  2107. \"-menu-\" in its name\)."
  2108.   (interactive "e")
  2109.   (bookmark-popup-menu-and-apply-function
  2110.    'bookmark-delete "Delete Bookmark" event))
  2111.  
  2112.  
  2113. ;; Thanks to Roland McGrath for fixing menubar.el so that the
  2114. ;; following works, and for explaining what to do to make it work.
  2115.  
  2116. ;; We MUST autoload EACH form used to set up this variable's value, so
  2117. ;; that the whole job is done in loaddefs.el.
  2118.  
  2119. ;;;###autoload
  2120. (if bookmark-xemacsp
  2121.     (progn
  2122.       (defvar bookmark-xemacs-menu
  2123.     '("Bookmarks"
  2124.       ["Jump to bookmark"            bookmark-menu-jump t]
  2125.       ["Set bookmark"            bookmark-set t]
  2126.       "---"
  2127.       ["Insert contents"            bookmark-menu-insert t]
  2128.       ["Insert location"            bookmark-menu-locate t]
  2129.       "---"
  2130.       ["Rename bookmark"            bookmark-menu-rename t]
  2131.       ["Delete bookmark"            bookmark-menu-delete t]
  2132.       ["Edit Bookmark List"       bookmark-bmenu-list t]
  2133.       "---"
  2134.       ["Save bookmarks"           bookmark-save t]
  2135.       ["Save bookmarks as..."     bookmark-write t]
  2136.       ["Load a bookmark file"     bookmark-load t]))
  2137.       ;; Display a solid horizontal line 
  2138.       ;;(add-menu-button '("File") ["---" nil nil] "Insert File...")
  2139.       ;;(add-submenu '("File") bookmark-xemacs-menu "Insert File...")
  2140.       (add-submenu '() bookmark-xemacs-menu "Apps")
  2141.       )
  2142.   
  2143.   ;; Emacs menubar stuff
  2144.   (defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions"))
  2145.   (defalias 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
  2146.  
  2147.   ;; make bookmarks appear toward the right side of the menu.
  2148.   (if (boundp 'menu-bar-final-items)
  2149.       (if menu-bar-final-items 
  2150.       (setq menu-bar-final-items
  2151.         (cons 'bookmark menu-bar-final-items)))
  2152.     (setq menu-bar-final-items '(bookmark)))
  2153.   
  2154.   (define-key menu-bar-bookmark-map [load]
  2155.     '("Load a bookmark file" . bookmark-load))
  2156.   (define-key menu-bar-bookmark-map [write]
  2157.     '("Save bookmarks as..." . bookmark-write))
  2158.   (define-key menu-bar-bookmark-map [save]
  2159.     '("Save bookmarks" . bookmark-save))
  2160.   (define-key menu-bar-bookmark-map [edit]
  2161.     '("Edit Bookmark List" . bookmark-bmenu-list))
  2162.   (define-key menu-bar-bookmark-map [delete]
  2163.     '("Delete bookmark" . bookmark-menu-delete))
  2164.   (define-key menu-bar-bookmark-map [rename]
  2165.     '("Rename bookmark" . bookmark-menu-rename))
  2166.   (define-key menu-bar-bookmark-map [locate]
  2167.     '("Insert location" . bookmark-menu-locate))
  2168.   (define-key menu-bar-bookmark-map [insert]
  2169.     '("Insert contents" . bookmark-menu-insert))
  2170.   (define-key menu-bar-bookmark-map [set]
  2171.     '("Set bookmark" . bookmark-set))
  2172.   (define-key menu-bar-bookmark-map [jump] 
  2173.     '("Jump to bookmark" . bookmark-menu-jump)))
  2174.  
  2175.  
  2176. ;;;; end bookmark menu stuff ;;;;
  2177.  
  2178.  
  2179. ;;; Load Hook
  2180. (defvar bookmark-load-hook nil
  2181.   "Hook to run at the end of loading bookmark.")
  2182.  
  2183. (run-hooks 'bookmark-load-hook)
  2184.  
  2185. (provide 'bookmark)
  2186.       
  2187. ;;; bookmark.el ends here
  2188.